/*
 *所有关于Quality_Daily_Report类的业务代码应在此处编写
*可使用repository.调用常用方法，获取EF/Dapper等信息
*如果需要事务请使用repository.DbContextBeginTransaction
*也可使用DBServerProvider.手动获取数据库相关信息
*用户信息、权限、角色等使用UserContext.Current操作
*Quality_Daily_ReportService对增、删、改查、导入、导出、审核业务代码扩展参照ServiceFunFilter
*/
using DGZImp.Core.BaseProvider;
using DGZImp.Core.Extensions.AutofacManager;
using ATkg.BizAppProject.DomainModels;
using System.Linq;
using DGZImp.Core.Utilities;
using System.Linq.Expressions;
using DGZImp.Core.Extensions;


using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using ATkg.BizAppProject.IRepositories;
using DGZImp.Core.Exceptions;
using Newtonsoft.Json.Linq;
using static ATkg.BizAppProject.Services.AmesSyncService;
using static ATkg.BizAppProject.Controllers.Quality_Daily_ReportController;


namespace ATkg.BizAppProject.Services
{
    public partial class Quality_Daily_ReportService
    {
        private readonly IHttpContextAccessor _httpContextAccessor;
        private readonly IQuality_Daily_ReportRepository _repository;//访问数据库
        private readonly AmesSyncService _amesSyncService;

        [ActivatorUtilitiesConstructor]
        public Quality_Daily_ReportService(  //依赖注入
            IQuality_Daily_ReportRepository dbRepository,
            IHttpContextAccessor httpContextAccessor,
            AmesSyncService amesSyncService
            )
        : base(dbRepository)
        {
            _httpContextAccessor = httpContextAccessor;
            _repository = dbRepository;
            _amesSyncService = amesSyncService;
            //多租户会用到这init代码，其他情况可以不用
            //base.Init(dbRepository);
        }

        public async Task<List<QualityResultAdd>> SyncQualityDailyReport_KongGang(string name)
        {

            var qDomain = new List<object>
            {
                "&", // AND 条件
                new List<object> { "wave_id", "!=", false },
                new List<object> { "wave_id", "ilike", name }
            };


            var qFields = new List<string> {
                "id",
                "wave_id",//生产波次
                "inspection_time",//检测日期
                "product_id",//产品
                "grade",//性能
                "plating",//镀层
                "blank_lot_name",//炉号
                "specification",//规格
                "atm_month",//安泰月
                "schedule_id",//订单号
                "outgoing_final_qty",//投料数
                "incoming_qualified_final_qty",//合格数

                "defect_blank_qty",//毛坯不良
                "defect_grinding_qty",//磨加工不良
                "defect_punching_qty",//打掏孔不良
                "defect_linear_qty",//线切割不良
                "defect_cute_qty",//切方不良
                "defect_variable_qty",//异形磨不良
                "defect_fringe_qty",//平磨不良
                "defect_slice_qty",//切片不良
                "defect_chamfer_qty",//倒角不良
                "defect_plating_qty",//电镀不良
                //"defect_permeation_qty",//渗透不良
                "rework_defect_qty",//电镀可返不良
                "chip_final_qty",//电镀检出崩边
                "defect_black_final_qty",//电镀检出黑磕
                "plating_check_fall_qty",//检包落地片
                "magnetization_fall_qty",//充磁不良
                "sampling_reliability_qty",//送测样品
                "material_eb_qty",//毛坯磕边
                "material_crack_qty",//毛坯裂纹
                "material_dit_qty",//毛坯砂眼
                //"material_impurity_qty",//毛坯杂质
                "material_lightspot_qty",//毛坯亮点
                "material_silicone_oil_qty",//毛坯硅油
                "material_flux_bad_qty",//毛坯磁通不良
                "material_oxygen_qty",//毛坯氧化
                "material_misc_qty",//黑皮/退料
                "defect_grinding_eb_qty",//磨加工磕边
                "defect_grinding_process_qty",//磨加工工残
                "defect_punching_eb_qty",//打掏孔磕边
                "defect_punching_process_qty",//打掏孔工残
                "defect_fringe_eb_qty",//平磨磕边
                "defect_fringe_process_qty",//平磨工残
                "defect_linear_eb_qty",//线切割磕边
                "defect_linear_process_qty",//线切割工残
                "defect_cute_eb_qty",//切方磕边
                "defect_cute_process_qty",//切方工残
                "defect_variable_eb_qty",//异形磨磕边
                "defect_variable_process_qty",//异形磨工残
                "defect_variable_verticality_qty",//异形磨垂直度超差
                "defect_variable_pit_qty",//异形磨麻坑
                "defect_slice_eb_qty",//切片磕边
                "defect_slice_process_qty",//切片工残
                "defect_slice_mark_qty",//切片刀痕
                "defect_slice_verticality_qty",//切片垂直度超差
                "defect_slice_size_qty",//切片垂直度超差
                "defect_slice_pit_qty",//切片麻坑
                "defect_chamfer_eb_qty",//倒角磕边
                "defect_chamfer_process_qty",//倒角工残
                "defect_chamfer_pit_qty",//倒角工残
                "defect_chamfer_pit_qty",//倒角工残
                "defect_plating_concave_pit_qty",//电镀凹坑
                "defect_plating_colordiff_qty",//电镀镀层色差
                "defect_plating_size_qty",//电镀尺寸超差
                "defect_plating_flux_qty",//电镀结合力不良
                "defect_plating_edge_broken_qty",//电镀磕边
                "defect_plating_paint_qty",//喷涂集漆
                "defect_plating_net_qty",//喷涂粘网
                "defect_plating_foreign_qty",//喷涂异物
                "defect_plating_bubble_qty",//电镀气泡
                "defect_plating_pit_qty",//电镀麻坑
                "defect_plating_disability_qty",//电镀镀残
                "rework_test_qty",//可返实验
                "rework_colordiff_qty",//可返镀层色差
                "rework_scratch_qty",//可返镀层划痕
                "rework_blister_qty",//可返起泡
                "rework_outoftol_qty",//可返超差
                "rework_edge_broken_qty",//可返磕边
                "rework_pit_qty",//可返凹坑
                "rework_paint_qty",//可返集漆
                "rework_foreign_qty",//可返异物
                "rework_net_qty",//可返粘网
                "rework_plating_paint_qty",//可返电镀掉漆

            };
            var qPage = new
            {
                context = new { lang = "zh_CN", tz = "Asia/Shanghai" },
                limit = 10000,
                offset = 0
            };
            var resp = await _amesSyncService.CallSearchRead("atm.qc.inspect.visual.rate.report",
                                                            qDomain,
                                                            qFields,
                                                            qPage);


            if (resp.ContainsKey("error"))
            {
                var message = $"【拉取单据】{resp["error"].ToString()}";
                throw new AppException(message);
            }
            var res = (JArray)resp["result"];

            if (res == null || res.Count <= 0)
            {
                return null;
            }
            var r = new List<QualityResultAdd>();

            for (var i = 0; i < res.Count; i++)
            {
                var x = (JObject)res[i];

                r.Add(new QualityResultAdd
                {
                    WaveId = x["wave_id"] is JArray ?
                                  (JArray.FromObject(x["wave_id"]).Count > 1 ?
                                   JArray.FromObject(x["wave_id"])[1].ToString() : "") :
                                  (x["wave_id"]?.ToString() ?? ""),
                    InspectionTime = x["inspection_time"]?.ToString() ?? "",
                    ProductId = x["product_id"]?.ToString() ?? "",
                    Grade = x["grade"]?.ToString() ?? "",
                    Plating = x["plating"]?.ToString() ?? "",
                    BlankLotName = x["blank_lot_name"]?.ToString() ?? "",
                    Spec = x["specification"]?.ToString() ?? "",
                    AtmMonth = x["atm_month"]?.ToString() ?? "",
                    ScheduleId = x["schedule_id"]?.ToString() ?? "",
                    OutgoingFinalQty = x["outgoing_final_qty"] != null ? (decimal)x["outgoing_final_qty"] : 0,
                    IncomingQualifiedFinalQty = x["incoming_qualified_final_qty"] != null ? (decimal)x["incoming_qualified_final_qty"] : 0,
                    DefectBlankQty = x["defect_blank_qty"] != null ? (decimal)x["defect_blank_qty"] : 0,
                    DefectGrindingQty = x["defect_grinding_qty"] != null ? (decimal)x["defect_grinding_qty"] : 0,
                    DefectPunchingQty = x["defect_punching_qty"] != null ? (decimal)x["defect_punching_qty"] : 0,
                    DefectLinearQty = x["defect_linear_qty"] != null ? (decimal)x["defect_linear_qty"] : 0,
                    DefectCuteQty = x["defect_cute_qty"] != null ? (decimal)x["defect_cute_qty"] : 0,
                    DefectVariableQty = x["defect_variable_qty"] != null ? (decimal)x["defect_variable_qty"] : 0,
                    DefectFringeQty = x["defect_fringe_qty"] != null ? (decimal)x["defect_fringe_qty"] : 0,
                    DefectSliceQty = x["defect_slice_qty"] != null ? (decimal)x["defect_slice_qty"] : 0,
                    DefectChamferQty = x["defect_chamfer_qty"] != null ? (decimal)x["defect_chamfer_qty"] : 0,
                    DefectPlatingQty = x["defect_plating_qty"] != null ? (decimal)x["defect_plating_qty"] : 0,
                    //DefectPermeationQty = x["defect_permeation_qty"] != null ? (decimal)x["defect_permeation_qty"] : 0,
                    ReworkDefectQty = x["rework_defect_qty"] != null ? (decimal)x["rework_defect_qty"] : 0,
                    ChipFinalQty = x["chip_final_qty"] != null ? (decimal)x["chip_final_qty"] : 0,
                    DefectBlackFinalQty = x["defect_black_final_qty"] != null ? (decimal)x["defect_black_final_qty"] : 0,
                    PlatingCheckFallQty = x["plating_check_fall_qty"] != null ? (decimal)x["plating_check_fall_qty"] : 0,
                    MagnetizationFallQty = x["magnetization_fall_qty"] != null ? (decimal)x["magnetization_fall_qty"] : 0,
                    SamplingReliabilityQty = x["sampling_reliability_qty"] != null ? (decimal)x["sampling_reliability_qty"] : 0,
                    MaterialEbQty = x["material_eb_qty"] != null ? (decimal)x["material_eb_qty"] : 0,
                    MaterialCrackQty = x["material_crack_qty"] != null ? (decimal)x["material_crack_qty"] : 0,
                    MaterialDitQty = x["material_dit_qty"] != null ? (decimal)x["material_dit_qty"] : 0,
                    //MaterialImpurityQty = x["material_impurity_qty"] != null ? (decimal)x["material_impurity_qty"] : 0,
                    MaterialLightspotQty = x["material_lightspot_qty"] != null ? (decimal)x["material_lightspot_qty"] : 0,
                    MaterialSiliconeOilQty = x["material_silicone_oil_qty"] != null ? (decimal)x["material_silicone_oil_qty"] : 0,
                    MaterialFluxBadQty = x["material_flux_bad_qty"] != null ? (decimal)x["material_flux_bad_qty"] : 0,
                    MaterialOxygenQty = x["material_oxygen_qty"] != null ? (decimal)x["material_oxygen_qty"] : 0,
                    MaterialMiscQty = x["material_misc_qty"] != null ? (decimal)x["material_misc_qty"] : 0,
                    DefectGrindingEbQty = x["defect_grinding_eb_qty"] != null ? (decimal)x["defect_grinding_eb_qty"] : 0,
                    DefectGrindingProcessQty = x["defect_grinding_process_qty"] != null ? (decimal)x["defect_grinding_process_qty"] : 0,
                    DefectPunchingEbQty = x["defect_punching_eb_qty"] != null ? (decimal)x["defect_punching_eb_qty"] : 0,
                    DefectPunchingProcessQty = x["defect_punching_process_qty"] != null ? (decimal)x["defect_punching_process_qty"] : 0,
                    DefectFringeEbQty = x["defect_fringe_eb_qty"] != null ? (decimal)x["defect_fringe_eb_qty"] : 0,
                    DefectFringeProcessQty = x["defect_fringe_process_qty"] != null ? (decimal)x["defect_fringe_process_qty"] : 0,
                    DefectLinearEbQty = x["defect_linear_eb_qty"] != null ? (decimal)x["defect_linear_eb_qty"] : 0,
                    DefectLinearProcessQty = x["defect_linear_process_qty"] != null ? (decimal)x["defect_linear_process_qty"] : 0,
                    DefectCuteEbQty = x["defect_cute_eb_qty"] != null ? (decimal)x["defect_cute_eb_qty"] : 0,
                    DefectCuteProcessQty = x["defect_cute_process_qty"] != null ? (decimal)x["defect_cute_process_qty"] : 0,
                    DefectVariableEbQty = x["defect_variable_eb_qty"] != null ? (decimal)x["defect_variable_eb_qty"] : 0,
                    DefectVariableProcessQty = x["defect_variable_process_qty"] != null ? (decimal)x["defect_variable_process_qty"] : 0,
                    DefectVariableVerticalityQty = x["defect_variable_verticality_qty"] != null ? (decimal)x["defect_variable_verticality_qty"] : 0,
                    DefectVariablePitQty = x["defect_variable_pit_qty"] != null ? (decimal)x["defect_variable_pit_qty"] : 0,
                    DefectSliceEbQty = x["defect_slice_eb_qty"] != null ? (decimal)x["defect_slice_eb_qty"] : 0,
                    DefectSliceProcessQty = x["defect_slice_process_qty"] != null ? (decimal)x["defect_slice_process_qty"] : 0,
                    DefectSliceMarkQty = x["defect_slice_mark_qty"] != null ? (decimal)x["defect_slice_mark_qty"] : 0,
                    DefectSliceVerticalityQty = x["defect_slice_verticality_qty"] != null ? (decimal)x["defect_slice_verticality_qty"] : 0,
                    DefectSliceSizeQty = x["defect_slice_size_qty"] != null ? (decimal)x["defect_slice_size_qty"] : 0,
                    DefectSlicePitQty = x["defect_slice_pit_qty"] != null ? (decimal)x["defect_slice_pit_qty"] : 0,
                    DefectChamferEbQty = x["defect_chamfer_eb_qty"] != null ? (decimal)x["defect_chamfer_eb_qty"] : 0,
                    DefectChamferProcessQty = x["defect_chamfer_process_qty"] != null ? (decimal)x["defect_chamfer_process_qty"] : 0,
                    DefectChamferPitQty = x["defect_chamfer_pit_qty"] != null ? (decimal)x["defect_chamfer_pit_qty"] : 0,
                    DefectPlatingConcavePitQty = x["defect_plating_concave_pit_qty"] != null ? (decimal)x["defect_plating_concave_pit_qty"] : 0,
                    DefectPlatingColordiffQty = x["defect_plating_colordiff_qty"] != null ? (decimal)x["defect_plating_colordiff_qty"] : 0,
                    DefectPlatingSizeQty = x["defect_plating_size_qty"] != null ? (decimal)x["defect_plating_size_qty"] : 0,
                    DefectPlatingFluxQty = x["defect_plating_flux_qty"] != null ? (decimal)x["defect_plating_flux_qty"] : 0,
                    DefectPlatingEdgeBrokenQty = x["defect_plating_edge_broken_qty"] != null ? (decimal)x["defect_plating_edge_broken_qty"] : 0,
                    DefectPlatingPaintQty = x["defect_plating_paint_qty"] != null ? (decimal)x["defect_plating_paint_qty"] : 0,
                    DefectPlatingNetQty = x["defect_plating_net_qty"] != null ? (decimal)x["defect_plating_net_qty"] : 0,
                    DefectPlatingForeignQty = x["defect_plating_foreign_qty"] != null ? (decimal)x["defect_plating_foreign_qty"] : 0,
                    DefectPlatingBubbleQty = x["defect_plating_bubble_qty"] != null ? (decimal)x["defect_plating_bubble_qty"] : 0,
                    DefectPlatingPitQty = x["defect_plating_pit_qty"] != null ? (decimal)x["defect_plating_pit_qty"] : 0,
                    DefectPlatingDisabilityQty = x["defect_plating_disability_qty"] != null ? (decimal)x["defect_plating_disability_qty"] : 0,
                    ReworkTestQty = x["rework_test_qty"] != null ? (decimal)x["rework_test_qty"] : 0,
                    ReworkColordiffQty = x["rework_colordiff_qty"] != null ? (decimal)x["rework_colordiff_qty"] : 0,
                    ReworkScratchQty = x["rework_scratch_qty"] != null ? (decimal)x["rework_scratch_qty"] : 0,
                    ReworkBlisterQty = x["rework_blister_qty"] != null ? (decimal)x["rework_blister_qty"] : 0,
                    ReworkOutoftolQty = x["rework_outoftol_qty"] != null ? (decimal)x["rework_outoftol_qty"] : 0,
                    ReworkEdgeBrokenQty = x["rework_edge_broken_qty"] != null ? (decimal)x["rework_edge_broken_qty"] : 0,
                    ReworkPitQty = x["rework_pit_qty"] != null ? (decimal)x["rework_pit_qty"] : 0,
                    ReworkPaintQty = x["rework_paint_qty"] != null ? (decimal)x["rework_paint_qty"] : 0,
                    ReworkForeignQty = x["rework_foreign_qty"] != null ? (decimal)x["rework_foreign_qty"] : 0,
                    ReworkNetQty = x["rework_net_qty"] != null ? (decimal)x["rework_net_qty"] : 0,
                    ReworkPlatingPaintQty = x["rework_plating_paint_qty"] != null ? (decimal)x["rework_plating_paint_qty"] : 0

                });

            }
            return r;
        }
        public async Task<List<QualityResultAdd>> SyncQualityDailyReport_AiKe(string name)
        {

            var qDomain = new List<object>
            {
                "&", // AND 条件
                new List<object> { "wave_id", "!=", false },
                new List<object> { "wave_id", "ilike", name }
            };


            var qFields = new List<string> {
                "id",
                "wave_id",//生产波次
                "inspection_time",//检测日期
                "product_id",//产品
                "grade",//性能
                "plating",//镀层
                "blank_lot_name",//炉号
                "specification",//规格
                "atm_month",//安泰月
                "schedule_id",//订单号
                "outgoing_final_qty",//投料数
                "incoming_qualified_final_qty",//合格数

                "defect_blank_qty",//毛坯不良
                "defect_grinding_qty",//磨加工不良
                "defect_punching_qty",//打掏孔不良
                "defect_linear_qty",//线切割不良
                "defect_cute_qty",//切方不良
                "defect_variable_qty",//异形磨不良
                "defect_fringe_qty",//平磨不良
                "defect_slice_qty",//切片不良
                "defect_chamfer_qty",//倒角不良
                "defect_plating_qty",//电镀不良
                //"defect_permeation_qty",//渗透不良
                "rework_defect_qty",//电镀可返不良
                "chip_final_qty",//电镀检出崩边
                "defect_black_final_qty",//电镀检出黑磕
                "plating_check_fall_qty",//检包落地片
                "magnetization_fall_qty",//充磁不良
                "sampling_reliability_qty",//送测样品
                "material_eb_qty",//毛坯磕边
                "material_crack_qty",//毛坯裂纹
                "material_dit_qty",//毛坯砂眼
                //"material_impurity_qty",//毛坯杂质
                "material_lightspot_qty",//毛坯亮点
                "material_silicone_oil_qty",//毛坯硅油
                "material_flux_bad_qty",//毛坯磁通不良
                "material_oxygen_qty",//毛坯氧化
                "material_misc_qty",//黑皮/退料
                "defect_grinding_eb_qty",//磨加工磕边
                "defect_grinding_process_qty",//磨加工工残
                "defect_punching_eb_qty",//打掏孔磕边
                "defect_punching_process_qty",//打掏孔工残
                "defect_fringe_eb_qty",//平磨磕边
                "defect_fringe_process_qty",//平磨工残
                "defect_linear_eb_qty",//线切割磕边
                "defect_linear_process_qty",//线切割工残
                "defect_cute_eb_qty",//切方磕边
                "defect_cute_process_qty",//切方工残
                "defect_variable_eb_qty",//异形磨磕边
                "defect_variable_process_qty",//异形磨工残
                "defect_variable_verticality_qty",//异形磨垂直度超差
                "defect_variable_pit_qty",//异形磨麻坑
                "defect_slice_eb_qty",//切片磕边
                "defect_slice_process_qty",//切片工残
                "defect_slice_mark_qty",//切片刀痕
                "defect_slice_verticality_qty",//切片垂直度超差
                "defect_slice_size_qty",//切片垂直度超差
                "defect_slice_pit_qty",//切片麻坑
                "defect_chamfer_eb_qty",//倒角磕边
                "defect_chamfer_process_qty",//倒角工残
                "defect_chamfer_pit_qty",//倒角麻坑
                "defect_plating_concave_pit_qty",//电镀凹坑
                "defect_plating_colordiff_qty",//电镀镀层色差
                "defect_plating_size_qty",//电镀尺寸超差
                "defect_plating_flux_qty",//电镀结合力不良
                "defect_plating_edge_broken_qty",//电镀磕边
                "defect_plating_paint_qty",//喷涂集漆
                "defect_plating_net_qty",//喷涂粘网
                "defect_plating_foreign_qty",//喷涂异物
                "defect_plating_bubble_qty",//电镀气泡
                "defect_plating_pit_qty",//电镀麻坑
                "defect_plating_disability_qty",//电镀镀残
                "rework_test_qty",//可返实验
                "rework_colordiff_qty",//可返镀层色差
                "rework_scratch_qty",//可返镀层划痕
                "rework_blister_qty",//可返起泡
                "rework_outoftol_qty",//可返超差
                "rework_edge_broken_qty",//可返磕边
                "rework_pit_qty",//可返凹坑
                "rework_paint_qty",//可返集漆
                "rework_foreign_qty",//可返异物
                "rework_net_qty",//可返粘网
                "rework_plating_paint_qty",//可返电镀掉漆

            };
            var qPage = new
            {
                context = new { lang = "zh_CN", tz = "Asia/Shanghai" },
                limit = 10000,
                offset = 0
            };

            var resp = await _amesSyncService.CallSearchRead_AiKe("atm.qc.inspect.visual.rate.report", qDomain, qFields, qPage);

            if (resp.ContainsKey("error"))
            {
                var message = $"【拉取单据】{resp["error"].ToString()}";
                throw new AppException(message);
            }
            var res = (JArray)resp["result"];

            if (res == null || res.Count <= 0)
            {
                return null;
            }
            var r = new List<QualityResultAdd>();

            for (var i = 0; i < res.Count; i++)
            {
                var x = (JObject)res[i];

                r.Add(new QualityResultAdd
                {
                    WaveId = x["wave_id"] is JArray ?
                                  (JArray.FromObject(x["wave_id"]).Count > 1 ?
                                   JArray.FromObject(x["wave_id"])[1].ToString() : "") :
                                  (x["wave_id"]?.ToString() ?? ""),
                    InspectionTime = x["inspection_time"]?.ToString() ?? "",
                    ProductId = x["product_id"]?.ToString() ?? "",
                    Grade = x["grade"]?.ToString() ?? "",
                    Plating = x["plating"]?.ToString() ?? "",
                    BlankLotName = x["blank_lot_name"]?.ToString() ?? "",
                    Spec = x["specification"]?.ToString() ?? "",
                    AtmMonth = x["atm_month"]?.ToString() ?? "",
                    ScheduleId = x["schedule_id"]?.ToString() ?? "",
                    OutgoingFinalQty = x["outgoing_final_qty"] != null ? (decimal)x["outgoing_final_qty"] : 0,
                    IncomingQualifiedFinalQty = x["incoming_qualified_final_qty"] != null ? (decimal)x["incoming_qualified_final_qty"] : 0,
                    DefectBlankQty = x["defect_blank_qty"] != null ? (decimal)x["defect_blank_qty"] : 0,
                    DefectGrindingQty = x["defect_grinding_qty"] != null ? (decimal)x["defect_grinding_qty"] : 0,
                    DefectPunchingQty = x["defect_punching_qty"] != null ? (decimal)x["defect_punching_qty"] : 0,
                    DefectLinearQty = x["defect_linear_qty"] != null ? (decimal)x["defect_linear_qty"] : 0,
                    DefectCuteQty = x["defect_cute_qty"] != null ? (decimal)x["defect_cute_qty"] : 0,
                    DefectVariableQty = x["defect_variable_qty"] != null ? (decimal)x["defect_variable_qty"] : 0,
                    DefectFringeQty = x["defect_fringe_qty"] != null ? (decimal)x["defect_fringe_qty"] : 0,
                    DefectSliceQty = x["defect_slice_qty"] != null ? (decimal)x["defect_slice_qty"] : 0,
                    DefectChamferQty = x["defect_chamfer_qty"] != null ? (decimal)x["defect_chamfer_qty"] : 0,
                    DefectPlatingQty = x["defect_plating_qty"] != null ? (decimal)x["defect_plating_qty"] : 0,
                    //DefectPermeationQty = x["defect_permeation_qty"] != null ? (decimal)x["defect_permeation_qty"] : 0,
                    ReworkDefectQty = x["rework_defect_qty"] != null ? (decimal)x["rework_defect_qty"] : 0,
                    ChipFinalQty = x["chip_final_qty"] != null ? (decimal)x["chip_final_qty"] : 0,
                    DefectBlackFinalQty = x["defect_black_final_qty"] != null ? (decimal)x["defect_black_final_qty"] : 0,
                    PlatingCheckFallQty = x["plating_check_fall_qty"] != null ? (decimal)x["plating_check_fall_qty"] : 0,
                    MagnetizationFallQty = x["magnetization_fall_qty"] != null ? (decimal)x["magnetization_fall_qty"] : 0,
                    SamplingReliabilityQty = x["sampling_reliability_qty"] != null ? (decimal)x["sampling_reliability_qty"] : 0,
                    MaterialEbQty = x["material_eb_qty"] != null ? (decimal)x["material_eb_qty"] : 0,
                    MaterialCrackQty = x["material_crack_qty"] != null ? (decimal)x["material_crack_qty"] : 0,
                    MaterialDitQty = x["material_dit_qty"] != null ? (decimal)x["material_dit_qty"] : 0,
                    //MaterialImpurityQty = x["material_impurity_qty"] != null ? (decimal)x["material_impurity_qty"] : 0,
                    MaterialLightspotQty = x["material_lightspot_qty"] != null ? (decimal)x["material_lightspot_qty"] : 0,
                    MaterialSiliconeOilQty = x["material_silicone_oil_qty"] != null ? (decimal)x["material_silicone_oil_qty"] : 0,
                    MaterialFluxBadQty = x["material_flux_bad_qty"] != null ? (decimal)x["material_flux_bad_qty"] : 0,
                    MaterialOxygenQty = x["material_oxygen_qty"] != null ? (decimal)x["material_oxygen_qty"] : 0,
                    MaterialMiscQty = x["material_misc_qty"] != null ? (decimal)x["material_misc_qty"] : 0,
                    DefectGrindingEbQty = x["defect_grinding_eb_qty"] != null ? (decimal)x["defect_grinding_eb_qty"] : 0,
                    DefectGrindingProcessQty = x["defect_grinding_process_qty"] != null ? (decimal)x["defect_grinding_process_qty"] : 0,
                    DefectPunchingEbQty = x["defect_punching_eb_qty"] != null ? (decimal)x["defect_punching_eb_qty"] : 0,
                    DefectPunchingProcessQty = x["defect_punching_process_qty"] != null ? (decimal)x["defect_punching_process_qty"] : 0,
                    DefectFringeEbQty = x["defect_fringe_eb_qty"] != null ? (decimal)x["defect_fringe_eb_qty"] : 0,
                    DefectFringeProcessQty = x["defect_fringe_process_qty"] != null ? (decimal)x["defect_fringe_process_qty"] : 0,
                    DefectLinearEbQty = x["defect_linear_eb_qty"] != null ? (decimal)x["defect_linear_eb_qty"] : 0,
                    DefectLinearProcessQty = x["defect_linear_process_qty"] != null ? (decimal)x["defect_linear_process_qty"] : 0,
                    DefectCuteEbQty = x["defect_cute_eb_qty"] != null ? (decimal)x["defect_cute_eb_qty"] : 0,
                    DefectCuteProcessQty = x["defect_cute_process_qty"] != null ? (decimal)x["defect_cute_process_qty"] : 0,
                    DefectVariableEbQty = x["defect_variable_eb_qty"] != null ? (decimal)x["defect_variable_eb_qty"] : 0,
                    DefectVariableProcessQty = x["defect_variable_process_qty"] != null ? (decimal)x["defect_variable_process_qty"] : 0,
                    DefectVariableVerticalityQty = x["defect_variable_verticality_qty"] != null ? (decimal)x["defect_variable_verticality_qty"] : 0,
                    DefectVariablePitQty = x["defect_variable_pit_qty"] != null ? (decimal)x["defect_variable_pit_qty"] : 0,
                    DefectSliceEbQty = x["defect_slice_eb_qty"] != null ? (decimal)x["defect_slice_eb_qty"] : 0,
                    DefectSliceProcessQty = x["defect_slice_process_qty"] != null ? (decimal)x["defect_slice_process_qty"] : 0,
                    DefectSliceMarkQty = x["defect_slice_mark_qty"] != null ? (decimal)x["defect_slice_mark_qty"] : 0,
                    DefectSliceVerticalityQty = x["defect_slice_verticality_qty"] != null ? (decimal)x["defect_slice_verticality_qty"] : 0,
                    DefectSliceSizeQty = x["defect_slice_size_qty"] != null ? (decimal)x["defect_slice_size_qty"] : 0,
                    DefectSlicePitQty = x["defect_slice_pit_qty"] != null ? (decimal)x["defect_slice_pit_qty"] : 0,
                    DefectChamferEbQty = x["defect_chamfer_eb_qty"] != null ? (decimal)x["defect_chamfer_eb_qty"] : 0,
                    DefectChamferProcessQty = x["defect_chamfer_process_qty"] != null ? (decimal)x["defect_chamfer_process_qty"] : 0,
                    DefectChamferPitQty = x["defect_chamfer_pit_qty"] != null ? (decimal)x["defect_chamfer_pit_qty"] : 0,
                    DefectPlatingConcavePitQty = x["defect_plating_concave_pit_qty"] != null ? (decimal)x["defect_plating_concave_pit_qty"] : 0,
                    DefectPlatingColordiffQty = x["defect_plating_colordiff_qty"] != null ? (decimal)x["defect_plating_colordiff_qty"] : 0,
                    DefectPlatingSizeQty = x["defect_plating_size_qty"] != null ? (decimal)x["defect_plating_size_qty"] : 0,
                    DefectPlatingFluxQty = x["defect_plating_flux_qty"] != null ? (decimal)x["defect_plating_flux_qty"] : 0,
                    DefectPlatingEdgeBrokenQty = x["defect_plating_edge_broken_qty"] != null ? (decimal)x["defect_plating_edge_broken_qty"] : 0,
                    DefectPlatingPaintQty = x["defect_plating_paint_qty"] != null ? (decimal)x["defect_plating_paint_qty"] : 0,
                    DefectPlatingNetQty = x["defect_plating_net_qty"] != null ? (decimal)x["defect_plating_net_qty"] : 0,
                    DefectPlatingForeignQty = x["defect_plating_foreign_qty"] != null ? (decimal)x["defect_plating_foreign_qty"] : 0,
                    DefectPlatingBubbleQty = x["defect_plating_bubble_qty"] != null ? (decimal)x["defect_plating_bubble_qty"] : 0,
                    DefectPlatingPitQty = x["defect_plating_pit_qty"] != null ? (decimal)x["defect_plating_pit_qty"] : 0,
                    DefectPlatingDisabilityQty = x["defect_plating_disability_qty"] != null ? (decimal)x["defect_plating_disability_qty"] : 0,
                    ReworkTestQty = x["rework_test_qty"] != null ? (decimal)x["rework_test_qty"] : 0,
                    ReworkColordiffQty = x["rework_colordiff_qty"] != null ? (decimal)x["rework_colordiff_qty"] : 0,
                    ReworkScratchQty = x["rework_scratch_qty"] != null ? (decimal)x["rework_scratch_qty"] : 0,
                    ReworkBlisterQty = x["rework_blister_qty"] != null ? (decimal)x["rework_blister_qty"] : 0,
                    ReworkOutoftolQty = x["rework_outoftol_qty"] != null ? (decimal)x["rework_outoftol_qty"] : 0,
                    ReworkEdgeBrokenQty = x["rework_edge_broken_qty"] != null ? (decimal)x["rework_edge_broken_qty"] : 0,
                    ReworkPitQty = x["rework_pit_qty"] != null ? (decimal)x["rework_pit_qty"] : 0,
                    ReworkPaintQty = x["rework_paint_qty"] != null ? (decimal)x["rework_paint_qty"] : 0,
                    ReworkForeignQty = x["rework_foreign_qty"] != null ? (decimal)x["rework_foreign_qty"] : 0,
                    ReworkNetQty = x["rework_net_qty"] != null ? (decimal)x["rework_net_qty"] : 0,
                    ReworkPlatingPaintQty = x["rework_plating_paint_qty"] != null ? (decimal)x["rework_plating_paint_qty"] : 0
                });

            }
            return r;
        }
        public async Task<List<QualityResultAdd>> SyncQualityDailyReport_BeiFang(string name)
        {

            var qDomain = new List<object>
            {
                "&", // AND 条件
                new List<object> { "wave_id", "!=", false },
                new List<object> { "wave_id", "ilike", name }
            };


            var qFields = new List<string> {
                "id",
                "wave_id",//生产波次
                "inspection_time",//检测日期
                "product_id",//产品
                "grade",//性能
                "plating",//镀层
                "blank_lot_name",//炉号
                "specification",//规格
                "atm_month",//安泰月
                "schedule_id",//订单号
                "outgoing_final_qty",//投料数
                "incoming_qualified_final_qty",//合格数

                "defect_blank_qty",//毛坯不良
                "defect_grinding_qty",//磨加工不良
                "defect_punching_qty",//打掏孔不良
                "defect_linear_qty",//线切割不良
                "defect_cute_qty",//切方不良
                "defect_variable_qty",//异形磨不良
                "defect_fringe_qty",//平磨不良
                "defect_slice_qty",//切片不良
                "defect_chamfer_qty",//倒角不良
                "defect_plating_qty",//电镀不良
                "defect_permeation_qty",//渗透不良
                "rework_defect_qty",//电镀可返不良
                "chip_final_qty",//电镀检出崩边
                "defect_black_final_qty",//电镀检出黑磕
                "plating_check_fall_qty",//检包落地片
                "magnetization_fall_qty",//充磁不良
                "sampling_reliability_qty",//送测样品
                "material_eb_qty",//毛坯磕边
                "material_crack_qty",//毛坯裂纹
                "material_dit_qty",//毛坯砂眼
                "material_impurity_qty",//毛坯杂质
                "material_lightspot_qty",//毛坯亮点
                "material_silicone_oil_qty",//毛坯硅油
                "material_flux_bad_qty",//毛坯磁通不良
                "material_oxygen_qty",//毛坯氧化
                "material_misc_qty",//黑皮/退料
                "defect_grinding_eb_qty",//磨加工磕边
                "defect_grinding_process_qty",//磨加工工残
                "defect_punching_eb_qty",//打掏孔磕边
                "defect_punching_process_qty",//打掏孔工残
                "defect_fringe_eb_qty",//平磨磕边
                "defect_fringe_process_qty",//平磨工残
                "defect_linear_eb_qty",//线切割磕边
                "defect_linear_process_qty",//线切割工残
                "defect_cute_eb_qty",//切方磕边
                "defect_cute_process_qty",//切方工残
                "defect_variable_eb_qty",//异形磨磕边
                "defect_variable_process_qty",//异形磨工残
                "defect_variable_verticality_qty",//异形磨垂直度超差
                "defect_variable_pit_qty",//异形磨麻坑
                "defect_slice_eb_qty",//切片磕边
                "defect_slice_process_qty",//切片工残
                "defect_slice_mark_qty",//切片刀痕
                "defect_slice_verticality_qty",//切片垂直度超差
                "defect_slice_size_qty",//切片垂直度超差
                "defect_slice_pit_qty",//切片麻坑
                "defect_chamfer_eb_qty",//倒角磕边
                "defect_chamfer_process_qty",//倒角工残
                "defect_chamfer_pit_qty",//倒角工残
                "defect_chamfer_pit_qty",//倒角工残
                "defect_plating_concave_pit_qty",//电镀凹坑
                "defect_plating_colordiff_qty",//电镀镀层色差
                "defect_plating_size_qty",//电镀尺寸超差
                "defect_plating_flux_qty",//电镀结合力不良
                "defect_plating_edge_broken_qty",//电镀磕边
                "defect_plating_paint_qty",//喷涂集漆
                "defect_plating_net_qty",//喷涂粘网
                "defect_plating_foreign_qty",//喷涂异物
                "defect_plating_bubble_qty",//电镀气泡
                "defect_plating_pit_qty",//电镀麻坑
                "defect_plating_disability_qty",//电镀镀残
                "rework_test_qty",//可返实验
                "rework_colordiff_qty",//可返镀层色差
                "rework_scratch_qty",//可返镀层划痕
                "rework_blister_qty",//可返起泡
                "rework_outoftol_qty",//可返超差
                "rework_edge_broken_qty",//可返磕边
                "rework_pit_qty",//可返凹坑
                "rework_paint_qty",//可返集漆
                "rework_foreign_qty",//可返异物
                "rework_net_qty",//可返粘网
                "rework_plating_paint_qty",//可返电镀掉漆

            };
            var qPage = new
            {
                context = new { lang = "zh_CN", tz = "Asia/Shanghai" },
                limit = 10000,
                offset = 0
            };

            var resp = await _amesSyncService.CallSearchRead_BeiFang("atm.qc.inspect.visual.rate.report", qDomain, qFields, qPage);

            if (resp.ContainsKey("error"))
            {
                var message = $"【拉取单据】{resp["error"].ToString()}";
                throw new AppException(message);
            }
            var res = (JArray)resp["result"];

            if (res == null || res.Count <= 0)
            {
                return null;
            }
            var r = new List<QualityResultAdd>();

            for (var i = 0; i < res.Count; i++)
            {
                try
                {
                    // 检查当前元素是否为空
                    if (res[i] == null)
                    {
                        Console.WriteLine($"第{i}个元素为空，跳过处理");
                        continue;
                    }

                    var x = res[i] as JObject;
                    if (x == null)
                    {
                        Console.WriteLine($"第{i}个元素无法转换为JObject，类型为：{res[i].GetType()}");
                        continue;
                    }

                    r.Add(new QualityResultAdd
                    {
                        WaveId = x["wave_id"] is JArray ?
                                  (JArray.FromObject(x["wave_id"]).Count > 1 ?
                                   JArray.FromObject(x["wave_id"])[1].ToString() : "") :
                                  (x["wave_id"]?.ToString() ?? ""),
                        InspectionTime = x["inspection_time"]?.ToString() ?? "",
                        ProductId = x["product_id"]?.ToString() ?? "",
                        Grade = x["grade"]?.ToString() ?? "",
                        Plating = x["plating"]?.ToString() ?? "",
                        BlankLotName = x["blank_lot_name"]?.ToString() ?? "",
                        Spec = x["specification"]?.ToString() ?? "",
                        AtmMonth = x["atm_month"]?.ToString() ?? "",
                        ScheduleId = x["schedule_id"]?.ToString() ?? "",
                        OutgoingFinalQty = x["outgoing_final_qty"] != null ? (decimal)x["outgoing_final_qty"] : 0,
                        IncomingQualifiedFinalQty = x["incoming_qualified_final_qty"] != null ? (decimal)x["incoming_qualified_final_qty"] : 0,
                        DefectBlankQty = x["defect_blank_qty"] != null ? (decimal)x["defect_blank_qty"] : 0,
                        DefectGrindingQty = x["defect_grinding_qty"] != null ? (decimal)x["defect_grinding_qty"] : 0,
                        DefectPunchingQty = x["defect_punching_qty"] != null ? (decimal)x["defect_punching_qty"] : 0,
                        DefectLinearQty = x["defect_linear_qty"] != null ? (decimal)x["defect_linear_qty"] : 0,
                        DefectCuteQty = x["defect_cute_qty"] != null ? (decimal)x["defect_cute_qty"] : 0,
                        DefectVariableQty = x["defect_variable_qty"] != null ? (decimal)x["defect_variable_qty"] : 0,
                        DefectFringeQty = x["defect_fringe_qty"] != null ? (decimal)x["defect_fringe_qty"] : 0,
                        DefectSliceQty = x["defect_slice_qty"] != null ? (decimal)x["defect_slice_qty"] : 0,
                        DefectChamferQty = x["defect_chamfer_qty"] != null ? (decimal)x["defect_chamfer_qty"] : 0,
                        DefectPlatingQty = x["defect_plating_qty"] != null ? (decimal)x["defect_plating_qty"] : 0,
                        //DefectPermeationQty = x["defect_permeation_qty"] != null ? (decimal)x["defect_permeation_qty"] : 0,
                        ReworkDefectQty = x["rework_defect_qty"] != null ? (decimal)x["rework_defect_qty"] : 0,
                        ChipFinalQty = x["chip_final_qty"] != null ? (decimal)x["chip_final_qty"] : 0,
                        DefectBlackFinalQty = x["defect_black_final_qty"] != null ? (decimal)x["defect_black_final_qty"] : 0,
                        PlatingCheckFallQty = x["plating_check_fall_qty"] != null ? (decimal)x["plating_check_fall_qty"] : 0,
                        MagnetizationFallQty = x["magnetization_fall_qty"] != null ? (decimal)x["magnetization_fall_qty"] : 0,
                        SamplingReliabilityQty = x["sampling_reliability_qty"] != null ? (decimal)x["sampling_reliability_qty"] : 0,
                        MaterialEbQty = x["material_eb_qty"] != null ? (decimal)x["material_eb_qty"] : 0,
                        MaterialCrackQty = x["material_crack_qty"] != null ? (decimal)x["material_crack_qty"] : 0,
                        MaterialDitQty = x["material_dit_qty"] != null ? (decimal)x["material_dit_qty"] : 0,
                        //MaterialImpurityQty = x["material_impurity_qty"] != null ? (decimal)x["material_impurity_qty"] : 0,
                        MaterialLightspotQty = x["material_lightspot_qty"] != null ? (decimal)x["material_lightspot_qty"] : 0,
                        MaterialSiliconeOilQty = x["material_silicone_oil_qty"] != null ? (decimal)x["material_silicone_oil_qty"] : 0,
                        MaterialFluxBadQty = x["material_flux_bad_qty"] != null ? (decimal)x["material_flux_bad_qty"] : 0,
                        MaterialOxygenQty = x["material_oxygen_qty"] != null ? (decimal)x["material_oxygen_qty"] : 0,
                        MaterialMiscQty = x["material_misc_qty"] != null ? (decimal)x["material_misc_qty"] : 0,
                        DefectGrindingEbQty = x["defect_grinding_eb_qty"] != null ? (decimal)x["defect_grinding_eb_qty"] : 0,
                        DefectGrindingProcessQty = x["defect_grinding_process_qty"] != null ? (decimal)x["defect_grinding_process_qty"] : 0,
                        DefectPunchingEbQty = x["defect_punching_eb_qty"] != null ? (decimal)x["defect_punching_eb_qty"] : 0,
                        DefectPunchingProcessQty = x["defect_punching_process_qty"] != null ? (decimal)x["defect_punching_process_qty"] : 0,
                        DefectFringeEbQty = x["defect_fringe_eb_qty"] != null ? (decimal)x["defect_fringe_eb_qty"] : 0,
                        DefectFringeProcessQty = x["defect_fringe_process_qty"] != null ? (decimal)x["defect_fringe_process_qty"] : 0,
                        DefectLinearEbQty = x["defect_linear_eb_qty"] != null ? (decimal)x["defect_linear_eb_qty"] : 0,
                        DefectLinearProcessQty = x["defect_linear_process_qty"] != null ? (decimal)x["defect_linear_process_qty"] : 0,
                        DefectCuteEbQty = x["defect_cute_eb_qty"] != null ? (decimal)x["defect_cute_eb_qty"] : 0,
                        DefectCuteProcessQty = x["defect_cute_process_qty"] != null ? (decimal)x["defect_cute_process_qty"] : 0,
                        DefectVariableEbQty = x["defect_variable_eb_qty"] != null ? (decimal)x["defect_variable_eb_qty"] : 0,
                        DefectVariableProcessQty = x["defect_variable_process_qty"] != null ? (decimal)x["defect_variable_process_qty"] : 0,
                        DefectVariableVerticalityQty = x["defect_variable_verticality_qty"] != null ? (decimal)x["defect_variable_verticality_qty"] : 0,
                        DefectVariablePitQty = x["defect_variable_pit_qty"] != null ? (decimal)x["defect_variable_pit_qty"] : 0,
                        DefectSliceEbQty = x["defect_slice_eb_qty"] != null ? (decimal)x["defect_slice_eb_qty"] : 0,
                        DefectSliceProcessQty = x["defect_slice_process_qty"] != null ? (decimal)x["defect_slice_process_qty"] : 0,
                        DefectSliceMarkQty = x["defect_slice_mark_qty"] != null ? (decimal)x["defect_slice_mark_qty"] : 0,
                        DefectSliceVerticalityQty = x["defect_slice_verticality_qty"] != null ? (decimal)x["defect_slice_verticality_qty"] : 0,
                        DefectSliceSizeQty = x["defect_slice_size_qty"] != null ? (decimal)x["defect_slice_size_qty"] : 0,
                        DefectSlicePitQty = x["defect_slice_pit_qty"] != null ? (decimal)x["defect_slice_pit_qty"] : 0,
                        DefectChamferEbQty = x["defect_chamfer_eb_qty"] != null ? (decimal)x["defect_chamfer_eb_qty"] : 0,
                        DefectChamferProcessQty = x["defect_chamfer_process_qty"] != null ? (decimal)x["defect_chamfer_process_qty"] : 0,
                        DefectChamferPitQty = x["defect_chamfer_pit_qty"] != null ? (decimal)x["defect_chamfer_pit_qty"] : 0,
                        DefectPlatingConcavePitQty = x["defect_plating_concave_pit_qty"] != null ? (decimal)x["defect_plating_concave_pit_qty"] : 0,
                        DefectPlatingColordiffQty = x["defect_plating_colordiff_qty"] != null ? (decimal)x["defect_plating_colordiff_qty"] : 0,
                        DefectPlatingSizeQty = x["defect_plating_size_qty"] != null ? (decimal)x["defect_plating_size_qty"] : 0,
                        DefectPlatingFluxQty = x["defect_plating_flux_qty"] != null ? (decimal)x["defect_plating_flux_qty"] : 0,
                        DefectPlatingEdgeBrokenQty = x["defect_plating_edge_broken_qty"] != null ? (decimal)x["defect_plating_edge_broken_qty"] : 0,
                        DefectPlatingPaintQty = x["defect_plating_paint_qty"] != null ? (decimal)x["defect_plating_paint_qty"] : 0,
                        DefectPlatingNetQty = x["defect_plating_net_qty"] != null ? (decimal)x["defect_plating_net_qty"] : 0,
                        DefectPlatingForeignQty = x["defect_plating_foreign_qty"] != null ? (decimal)x["defect_plating_foreign_qty"] : 0,
                        DefectPlatingBubbleQty = x["defect_plating_bubble_qty"] != null ? (decimal)x["defect_plating_bubble_qty"] : 0,
                        DefectPlatingPitQty = x["defect_plating_pit_qty"] != null ? (decimal)x["defect_plating_pit_qty"] : 0,
                        DefectPlatingDisabilityQty = x["defect_plating_disability_qty"] != null ? (decimal)x["defect_plating_disability_qty"] : 0,
                        ReworkTestQty = x["rework_test_qty"] != null ? (decimal)x["rework_test_qty"] : 0,
                        ReworkColordiffQty = x["rework_colordiff_qty"] != null ? (decimal)x["rework_colordiff_qty"] : 0,
                        ReworkScratchQty = x["rework_scratch_qty"] != null ? (decimal)x["rework_scratch_qty"] : 0,
                        ReworkBlisterQty = x["rework_blister_qty"] != null ? (decimal)x["rework_blister_qty"] : 0,
                        ReworkOutoftolQty = x["rework_outoftol_qty"] != null ? (decimal)x["rework_outoftol_qty"] : 0,
                        ReworkEdgeBrokenQty = x["rework_edge_broken_qty"] != null ? (decimal)x["rework_edge_broken_qty"] : 0,
                        ReworkPitQty = x["rework_pit_qty"] != null ? (decimal)x["rework_pit_qty"] : 0,
                        ReworkPaintQty = x["rework_paint_qty"] != null ? (decimal)x["rework_paint_qty"] : 0,
                        ReworkForeignQty = x["rework_foreign_qty"] != null ? (decimal)x["rework_foreign_qty"] : 0,
                        ReworkNetQty = x["rework_net_qty"] != null ? (decimal)x["rework_net_qty"] : 0,
                        ReworkPlatingPaintQty = x["rework_plating_paint_qty"] != null ? (decimal)x["rework_plating_paint_qty"] : 0
                    });
                }
                catch (InvalidCastException ex)
                {
                    Console.WriteLine($"第{i}个元素类型转换错误: {ex.Message}");
                    // 可以选择记录详细异常信息
                    // Logger.Error(ex, $"第{i}个元素处理失败");
                }
                catch (NullReferenceException ex)
                {
                    Console.WriteLine($"第{i}个元素空引用错误: {ex.Message}");
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine($"第{i}个元素参数错误: {ex.Message}");
                }
                catch (IndexOutOfRangeException ex)
                {
                    Console.WriteLine($"第{i}个元素索引超出范围: {ex.Message}");
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"处理第{i}个元素时发生未知错误: {ex.Message}");
                }

            }
            return r;
        }
    }
}
